package com.whcoding.base.project.service.impl;

import java.math.BigDecimal;

import com.google.common.collect.Lists;

import java.util.*;


import com.whcoding.base.project.common.BaseImplMockitoTest;
import com.whcoding.base.project.dao.DeptDao;
import com.whcoding.base.project.dao.DeptMapper;
import com.whcoding.base.project.pojo.OrmDeptVO;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;

/**
 * 添加Mockito 的简单使用
 */
public class DeptServiceImplTestImpl extends BaseImplMockitoTest {


	@InjectMocks
	DeptServiceImpl deptServiceIpml;

	@Mock
	DeptDao deptDao;

	@Mock
	DeptMapper deptMapper;

	/**
	 * 常用的Mock测试方法
	 */
	@Test
	public void deptMockitoTest() {
		OrmDeptVO deptVO = new OrmDeptVO();
		deptVO.setDeptId(2003);
		deptVO.setDeptNo("BJ_KF");
		deptVO.setDeptName("北京开发");
		deptVO.setDeptType(2);
		deptVO.setCreateTime(new Date());
		deptVO.setUpdateTime(new Date());
		deptVO.setDeptPerf(new BigDecimal("0"));
		deptVO.setIsValidFlag(1);
		deptVO.setShortName("北京开发");
		deptVO.setDeptNoList(Lists.newArrayList());
		//Mock返回值
		Mockito.when(deptMapper.queryDeptById(Mockito.anyLong())).thenReturn(deptVO);
		//没有返回值 传递Class
		Mockito.doNothing().when(deptMapper).updateOrmDept(Mockito.any(OrmDeptVO.class));

		Mockito.doNothing().when(deptMapper).updateDeptList(Mockito.anyMap());

		Mockito.when(deptDao.saveAll(Mockito.anyList())).thenReturn(null);

		Mockito.when(deptMapper.findDeptNameAndDeptNo(Mockito.anyList())).thenReturn(null);

		List<Map<String, Object>> mapList = new ArrayList<>();
		Map<String, Object> map = new HashMap();
		map.put("deptName", "deptName");
		map.put("deptCode", "deptCode");
		mapList.add(map);
		Mockito.when(deptMapper.findDeptNameAndDeptNo(Mockito.anyList())).thenReturn(mapList);

		Mockito.when(deptMapper.countByDeptByDeptName(Mockito.anyMap())).thenReturn(Mockito.anyInt());
		deptServiceIpml.queryAllDept();
	}

}
